package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-19 10:36
 **/
public class LeetCode5957 {

    public String addSpaces(String s, int[] spaces) {
        int index = 0;
        int n = spaces.length;

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (index < n && i == spaces[index]) {
                builder.append(" ").append(s.charAt(i));
                ++index;
            } else {
                builder.append(s.charAt(i));
            }
        }

        return builder.toString();
    }

    public static void main(String[] args) {
        LeetCode5957 code = new LeetCode5957();
        System.out.println(code.addSpaces("LeetcodeHelpsMeLearn", new int[]{8,13,15}));
    }

}
